from pyecharts import options as opts
from pyecharts.charts import Bar
from kit import *


def bar_plot_simple(all_data):
    x_name = input('请输入x轴名称')
    y_name = input('请输入y轴名称')
    c = (
        # 加了动画
        Bar(init_opts=opts.InitOpts(
            animation_opts=opts.AnimationOpts(
                animation_delay=100, animation_easing="elasticOut"
            )
        ))
            .set_global_opts(
            title_opts=opts.TitleOpts(title=all_data.name),
            yaxis_opts=opts.AxisOpts(name=y_name,  # y轴名称
                                     axislabel_opts=opts.LabelOpts(formatter="{value}")),  # 单位标注
            xaxis_opts=opts.AxisOpts(name=x_name),  # x轴名称
            datazoom_opts=opts.DataZoomOpts(orient="vertical", type_="inside"),  # 垂直 slider
        )
            # 标注最大值和最小值
            .set_series_opts(
            label_opts=opts.LabelOpts(is_show=False),
            markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_="min", name="最小值"),  # 这个用线拉
                ]
            ),
            markline_opts=opts.MarkLineOpts(
                data=[
                    opts.MarkLineItem(type_="max", name="最大值"),  # 这个点标注
                ]
            ),
        )

    )
    col = all_data.col_values(0)[1:]
    c.add_xaxis(col)
    for i in range(1, all_data.ncols):
        col = all_data.col_values(i)
        for mid in range(1, all_data.nrows):
            col[mid] = manage_data_to_area(col[mid])
        c.add_yaxis(col[0], col[1:])
    c.set_global_opts(toolbox_opts=opts.ToolboxOpts(),
                      datazoom_opts=opts.DataZoomOpts(range_start=1, range_end=300)
                      )
    c.render('bar_plot_simple.html')
